package com.athuiju.hr.service.impl;

import com.alibaba.nacos.client.utils.StringUtils;
import com.athuiju.hr.entity.Profiles;
import com.athuiju.hr.entity.vo.ProRessultVo;
import com.athuiju.hr.entity.vo.ProRessultVoQuery;
import com.athuiju.hr.mapper.ProfilesMapper;
import com.athuiju.hr.service.ProfilesService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wzh
 * @since 2021-12-15
 */
@Service
public class ProfilesServiceImpl extends ServiceImpl<ProfilesMapper, Profiles> implements ProfilesService {
    @Autowired
    ProfilesMapper profilesMapper;




    //离职员工当月离职统计
    @Override
    public Integer countPro() {
        return profilesMapper.countPro();
    }

    //员工当月入职统计
    @Override
    public Integer countFalse() {
        return profilesMapper.countFalse();
    }

    @Override
    public List<Profiles> getProId() {
        return profilesMapper.getProId();
    }

    //在职总人数
    @Override
    public Integer countFalsePro() {
        return profilesMapper.countFalsePro();
    }
//离职总人数
    @Override
    public Integer countProSum() {
        return profilesMapper.countProSum();
    }


    //根据id查询员工
    @Override
    public List<ProRessultVo> getByid(Integer id) {
       return    profilesMapper.getByid(id);
    }


    //在职员工条件分页查询方法,调用分页插件完成分页
    @Override
    public void pageQuery(Page<ProRessultVo> pageSture, ProRessultVoQuery proRessultVoQuery) {
        QueryWrapper<ProRessultVo> queryWrapper=new QueryWrapper<>();
        //当模糊查询条件为null时，就显示pageSture里面的所有数据
        if (proRessultVoQuery== null) {
            baseMapper.selectMyPage(pageSture,null);
            return;
        }
        String name=proRessultVoQuery.getName();
        String begin=proRessultVoQuery.getBegin();
        String end=proRessultVoQuery.getEnd();
        String organization = proRessultVoQuery.getOrganization();
        String post = proRessultVoQuery.getPost();
        String sector = proRessultVoQuery.getSector();

        //根据姓名查询
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("p.name",name);
        }
        //根据创建时间查询
        if (!StringUtils.isEmpty(begin)){
            queryWrapper.gt("p.gmt_create",begin);
        }
        //根据修改时间查询
        if (!StringUtils.isEmpty(end)){
            queryWrapper.lt("p.gmt_modified",end);
        }
        //根据组织查询
        if (!StringUtils.isEmpty(organization)){
            queryWrapper.like(" `organization`.organization",organization);
        }
        //根据部门查询
        if (!StringUtils.isEmpty(post)){
            queryWrapper.like("p.postid",post);
        }
        //根据职位查询
        if (!StringUtils.isEmpty(sector)){
            queryWrapper.like("p.sectorid",sector);
        }
        //日期倒序排序
        queryWrapper.orderByDesc("p.gmt_modified");
        baseMapper.selectMyPage(pageSture,queryWrapper);
    }

    /**
     * 离职员工条件分页查询方法 */
    @Override
    public void pageQueryPro(Page<ProRessultVo> pageSture, ProRessultVoQuery proRessultVoQuery) {
        QueryWrapper<ProRessultVo> queryWrapper=new QueryWrapper<>();
        if (proRessultVoQuery== null) {
            baseMapper.selectMyPageDimission(pageSture,null);
            return;
        }
        String name=proRessultVoQuery.getName();
        String begin=proRessultVoQuery.getBegin();
        String end=proRessultVoQuery.getEnd();
        String organization = proRessultVoQuery.getOrganization();
        String post = proRessultVoQuery.getPost();
        String sector = proRessultVoQuery.getSector();
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("p.name",name);
        }
        if (!StringUtils.isEmpty(begin)){
            queryWrapper.gt("p.gmt_create",begin);
        }
        if (!StringUtils.isEmpty(end)){
            queryWrapper.lt("p.gmt_modified",end);
        }
        if (!StringUtils.isEmpty(organization)){
            queryWrapper.like(" `organization`.organization",organization);
        }
        if (!StringUtils.isEmpty(post)){
            queryWrapper.like("p.postid",post);
        }
        if (!StringUtils.isEmpty(sector)){
            queryWrapper.like("p.sectorid",sector);
        }
      //日期倒序排序
        queryWrapper.orderByDesc("p.gmt_modified");
        baseMapper.selectMyPageDimission(pageSture,queryWrapper);
    }


}
